﻿@model NapCardOnline.Models.TransferFund
@using MvcUtil
@{
    ViewBag.Title = "Chuyển tiền";
    Layout = "~/Views/Shared/_LayoutUser.cshtml";
}
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
    $(document).ready(function() {
        $('#ToUser').autocomplete({
            source: "/TransferFund/GetAutosuggestByUserName/",
            minLength: 1,
        });
    });

        $(function() {
        $("form").submit(function (e) {
            e.preventDefault();
            var transferFundAmount = $("#TransferFundAmount").val().replace(/,/g, '');
            var transferFund = {
                TransferFundAmount: transferFundAmount,
                ToUser: $("#ToUser").val(),
                TransferFundDesc: $("#TransferFundDesc").val(),
            };
            $("#TransferFundAmount").val(transferFundAmount);
            $.ajax({
                url: '@Url.Action("CheckUser", "TransferFund")',
                data: { userName: $("#ToUser").val(), amount: transferFundAmount},
                type: 'POST',
                success: function (data) {
                    if (!data.ischeck) {
                        if(data.name=="touser" || data.name=="transfer") {
                            $("#ToUser").focus();
                            $(".control-group").eq(1).addClass("control-group error");
                            $("span[data-valmsg-for='ToUser']").removeClass("field-validation-valid");
                            $("span[data-valmsg-for='ToUser']").addClass("field-validation-error");
                            $("span[data-valmsg-for='ToUser']").text(data.success); 
                        } else if(data.name=="balance") {
                            $("#TransferFundAmount").focus();
                            $("span[data-valmsg-for='TransferFundAmount']").removeClass("field-validation-valid");
                            $("span[data-valmsg-for='TransferFundAmount']").addClass("field-validation-error");
                            $("span[data-valmsg-for='TransferFundAmount']").text(data.success); 
                        }
                       
                    } else {
                        $.ajax({
                            url: '@Url.Action("Create", "TransferFund")',
                            data:JSON.stringify(transferFund),
                            type: 'POST',
                            contentType:'application/json; charset=utf-8',
                            dataType:'json',
                            success: function (data) {
                                alert(data.info);
                                window.location.reload();
                            },
                        });
                    }
                },
                error: function () {
                },

            });
        });
        
    });

</script>
<div class="row">
    <fieldset>
        <legend>Chyển tiền</legend>
        <div class="alert">
            <button type="button" class="close" data-dismiss="alert">
                &times;</button>
            <strong>Chú ý!</strong>
            <ul>
                <li>Phần * là bắt buộc.</li>
                <li>NapCardOnline không chịu trách nhiệm khi quí khách chuyển sai tiền cho người khác.</li>
                <li>Quí khách nên đọc kỹ điều khoản sử dụng trước khi thực hiện thao tác này.</li>
            </ul>
        </div>
        <div class="span6">
            @using (Html.BeginForm("Create", "TransferFund", FormMethod.Post, new { @class = "form-horizontal" }))
            {
                @Html.ValidationSummary(true)
                <small class="pull-left" style="margin-top: 20px;">
                    <div class="control-group">
                        <label for="TransferFundAmount" class="control-label">
                            Số tiền chuyển * :</label>
                        <div class="controls">
                            @Html.EditorFor(model => model.TransferFundAmount, "EditorTemplates/Double", new { @class = "format-price keypress-number", @maxlength = "9", @required = "required" })
                            <br />
                            @Html.ValidationMessageFor(model => model.TransferFundAmount)
                        </div>
                    </div>
                    <div class="control-group">
                        <label for="FK_ToUserID" class="control-label" title="Tài khoản nhận">
                            Tài khoản nhận * :</label>
                        <div class="controls">
                            @Html.EditorFor(model => model.ToUser, "EditorTemplates/String", new { @placeholder = "Reciver Account", @required = "required", @title = "Tài khoản nhận", @class = "ui-autocomplete" })
                            <br />
                            @Html.ValidationMessageFor(model => model.ToUser)
                        </div>
                    </div>
                    <div class="control-group">
                        <label for="TransferFundDesc" class="control-label" title="Nội dung">
                            Nội dung * :</label>
                        <div class="controls">
                            @Html.TextAreaFor(model => model.TransferFundDesc, 3, 40, new { @placeholder = "Description", @title = "Nội dung chuyển tiền:", @required = "required" })
                            @Html.ValidationMessageFor(model => model.TransferFundDesc)
                        </div>
                        <br />
                        <div class="controls">
                            <input type="submit" class="btn btn-primary" value="Gửi yêu cầu" />
                        </div>
                    </div>
                </small>
            }
        </div>
        <div class="span5">
            <small class="pull-right" style="margin-left: 20px;">
                <img src=@Url.Content("~/Content/themes/base/images/transfermoney.jpg") id="irc_mi" style="margin-top: 0px;" width="457" height="155" />
            </small>
        </div>
    </fieldset>
</div>
